import {httpInstance} from "@/utils/http.js";
import {ref} from "vue";

// 上传课程表图片
export function userUpload(userId, userName, file) {
    const formData = new FormData();
    formData.append('file', file);
    formData.append('name', userName);
    formData.entries()
    return httpInstance({
        url: "/user/upload_img",
        method: "post",
        headers: {
            'Content-Type': 'multipart/form-data;',
            key: userId
        },
        data: formData
    })
}

// 获取课程表
export function userGetTable(id) {
    return httpInstance({
        url: "/user/get_table",
        method: "get",
        headers: {
            submitId: id,
        }
    })
}
// 修改课程表
export function userUpdateTable(submitId, table) {
    return httpInstance({
        url: "/user/update_table",
        method: "put",
        headers: {
            submitId: submitId
        },
        data: {
            table: table
        }
    })
}

// 检查素有submitId合法性
export function userSubmitIdValidate(submitIdList) {
    if (submitIdList.value == null) {
        submitIdList = ref([])
    }
    return httpInstance({
        url: "/user/submit_ids/validate",
        method: "post",
        data: {
            submitIds: submitIdList.value
        }
    })
}

// 直接上传课程表
export function userUploadTable(key, table, name) {
    return httpInstance({
        url: "/user/upload_table",
        method: "post",
        headers: {
            key: key
        },
        data: {
            name: name,
            table: table
        }
    })
}